package com.ruoyi.oa.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.oa.domain.OaApplyRecord;
import com.ruoyi.oa.service.IOaApplyRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用车记录Controller
 * 
 * @author allen
 * @date 2025-01-04
 */
@RestController
@RequestMapping("/oa/applyrecord")
public class OaApplyRecordController extends BaseController
{
    @Autowired
    private IOaApplyRecordService oaApplyRecordService;

    /**
     * 查询用车记录列表
     */
    @PreAuthorize("@ss.hasPermi('oa:applyrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaApplyRecord oaApplyRecord)
    {
        startPage();
        List<OaApplyRecord> list = oaApplyRecordService.selectOaApplyRecordList(oaApplyRecord);
        return getDataTable(list);
    }

    /**
     * 导出用车记录列表
     */
    @PreAuthorize("@ss.hasPermi('oa:applyrecord:export')")
    @Log(title = "用车记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaApplyRecord oaApplyRecord)
    {
        List<OaApplyRecord> list = oaApplyRecordService.selectOaApplyRecordList(oaApplyRecord);
        ExcelUtil<OaApplyRecord> util = new ExcelUtil<OaApplyRecord>(OaApplyRecord.class);
        util.exportExcel(response, list, "用车记录数据");
    }

    /**
     * 获取用车记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('oa:applyrecord:query')")
    @GetMapping(value = "/{applyId}")
    public AjaxResult getInfo(@PathVariable("applyId") Long applyId)
    {
        return success(oaApplyRecordService.selectOaApplyRecordByApplyId(applyId));
    }

    /**
     * 新增用车记录
     */
    @PreAuthorize("@ss.hasPermi('oa:applyrecord:add')")
    @Log(title = "用车记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaApplyRecord oaApplyRecord)
    {
        return toAjax(oaApplyRecordService.insertOaApplyRecord(oaApplyRecord));
    }

    /**
     * 修改用车记录
     */
    @PreAuthorize("@ss.hasPermi('oa:applyrecord:edit')")
    @Log(title = "用车记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaApplyRecord oaApplyRecord)
    {
        return toAjax(oaApplyRecordService.updateOaApplyRecord(oaApplyRecord));
    }

    /**
     * 删除用车记录
     */
    @PreAuthorize("@ss.hasPermi('oa:applyrecord:remove')")
    @Log(title = "用车记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applyIds}")
    public AjaxResult remove(@PathVariable Long[] applyIds)
    {
        return toAjax(oaApplyRecordService.deleteOaApplyRecordByApplyIds(applyIds));
    }
}
